package com.wiz.data.vo.to;


/**
 * double数字域
 * @author Hakeny
 */
public class MessageDoubleFiled extends MessageFiled {

	@Override
	public byte[] toBytes() {
		double doubleValue = (double)value;
		long sum = Double.doubleToLongBits(doubleValue);
		byte[] arr = new byte[8];
        arr[0] = (byte) (sum >> 56);
        arr[1] = (byte) (sum >> 48);
        arr[2] = (byte) (sum >> 40);
        arr[3] = (byte) (sum >> 32);
        arr[4] = (byte) (sum >> 24);
        arr[5] = (byte) (sum >> 16);
        arr[6] = (byte) (sum >> 8);
        arr[7] = (byte) (sum & 0xff);
		return arr;
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		MessageDoubleFiled filed = (MessageDoubleFiled) super.clone();
		filed.setType(this.type);
//		filed.setValue(this.value);
		filed.setNeedLength(this.needLength);
		return filed;
	}
	
	public static void main(String[] args) {
		long sum = Double.doubleToLongBits(3.1415926);
		 byte[] arr = new byte[8];
	        arr[0] = (byte) (sum >> 56);
	        arr[1] = (byte) (sum >> 48);
	        arr[2] = (byte) (sum >> 40);
	        arr[3] = (byte) (sum >> 32);
	        arr[4] = (byte) (sum >> 24);
	        arr[5] = (byte) (sum >> 16);
	        arr[6] = (byte) (sum >> 8);
	        arr[7] = (byte) (sum & 0xff);
	        
//	        long s0 = (arr[0] & 0xff) << 56;// 最低位 
//	        long s1 = (arr[1] & 0xff) << 48; 
//	        long s2 = (arr[2] & 0xff) << 40; 
//	        long s3 = (arr[3] & 0xff) << 32; 
//	        long s4 = (arr[4] & 0xff) << 24;// 最低位 
//	        long s5 = (arr[5] & 0xff) << 16; 
//	        long s6 = (arr[6] & 0xff) << 8; 
//	        long s7 = arr[7] & 0xff; 
	 
//	        s = s0 | s1 | s2 | s3 | s4 | s5 | s6 | s7; 
	        
	        long s = (((long) (arr[0] & 0xff) << 56) | ((long) (arr[1] & 0xff) << 48) | ((long) (arr[2] & 0xff) << 40)
                    | ((long) (arr[3] & 0xff) << 32) | ((long) (arr[4] & 0xff) << 24)
                    | ((long) (arr[5] & 0xff) << 16) | ((long) (arr[6] & 0xff) << 8) | ((long) (arr[7] & 0xff)));
	        
	        System.out.println(Double.longBitsToDouble(s));
	}
}
